package com.liuzu.esys.controller;

import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.common.R;
import com.liuzu.esys.pojo.Grade;
import com.liuzu.esys.service.GradeService;
import com.liuzu.esys.vo.ColumnarPieVo;
import com.liuzu.esys.vo.ColumnarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/grade")
public class GradeController {
    @Autowired
    private GradeService gradeService;
    //分页和模糊查询的接口
    @RequestMapping("/gradeList")
    public LayuiPageVo<Grade> userPageData(@RequestParam Map<String,Object> params){
        //System.out.println(params);
        return gradeService.gradePageData(params);
    }
    //添加合作商等级
    @RequestMapping("/addGrade")
    public R addGrade(Grade grade){
        //System.out.println(grade);
        int i = gradeService.addGrade(grade);
        if (i == 1) {
            return R.ok();
        }else {
            return R.error();
        }

    }
    //删除合作商等级
    @RequestMapping("/deleteGrade")
    public R deleteGrade(Integer phone){
       // System.out.println(phone);
        int i = gradeService.deleteGrade(phone);
        if (i == 1) {
            return R.ok();
        }else{
            return R.error();
        }

    }
    //修改合作商等级
    @RequestMapping("/updateGrade")
    public R updateGrade(Grade grade){
        //System.out.println(grade);
        int i = gradeService.updateGrade(grade);
        if (i == 1) {
            return R.ok();

        }else {
            return R.error();
        }

    }
    //合作商等级柱状图
    @RequestMapping("/columnarVo")
    public R ColumnarVo() {
        List<ColumnarVo> list = gradeService.ageBarData();
        return R.ok().data("ageBar", list);
    }
    //合作商等级饼状图
    @RequestMapping("/columnarPicVo")
    public R columnarPicVo() {
        List<ColumnarPieVo> list = gradeService.agePieData();

        return R.ok().data("agePie", list);


    }
}
